(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^3).


The TRS R consists of the following rules:

sort(nil) → nil
sort(cons(x, y)) → insert(x, sort(y))
insert(x, nil) → cons(x, nil)
insert(x, cons(v, w)) → choose(x, cons(v, w), x, v)
choose(x, cons(v, w), y, 0) → cons(x, cons(v, w))
choose(x, cons(v, w), 0, s(z)) → cons(v, insert(x, w))
choose(x, cons(v, w), s(y), s(z)) → choose(x, cons(v, w), y, z)

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^3).


The TRS R consists of the following rules:

sort(nil) → nil [1]
sort(cons(x, y)) → insert(x, sort(y)) [1]
insert(x, nil) → cons(x, nil) [1]
insert(x, cons(v, w)) → choose(x, cons(v, w), x, v) [1]
choose(x, cons(v, w), y, 0) → cons(x, cons(v, w)) [1]
choose(x, cons(v, w), 0, s(z)) → cons(v, insert(x, w)) [1]
choose(x, cons(v, w), s(y), s(z)) → choose(x, cons(v, w), y, z) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

sort(nil) → nil [1]
sort(cons(x, y)) → insert(x, sort(y)) [1]
insert(x, nil) → cons(x, nil) [1]
insert(x, cons(v, w)) → choose(x, cons(v, w), x, v) [1]
choose(x, cons(v, w), y, 0) → cons(x, cons(v, w)) [1]
choose(x, cons(v, w), 0, s(z)) → cons(v, insert(x, w)) [1]
choose(x, cons(v, w), s(y), s(z)) → choose(x, cons(v, w), y, z) [1]

The TRS has the following type information:
sort :: nil:cons → nil:cons
nil :: nil:cons
cons :: 0:s → nil:cons → nil:cons
insert :: 0:s → nil:cons → nil:cons
choose :: 0:s → nil:cons → 0:s → 0:s → nil:cons
0 :: 0:s
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The transformation into a RNTS is sound, since:

(a) The obligation is a constructor system where every type has a constant constructor,

(b) The following defined symbols do not have to be completely defined, as they can never occur inside other defined symbols:
none

(c) The following functions are completely defined:


sort
insert
choose

Due to the following rules being added:

choose(v0, v1, v2, v3) → nil [0]

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where critical functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

sort(nil) → nil [1]
sort(cons(x, y)) → insert(x, sort(y)) [1]
insert(x, nil) → cons(x, nil) [1]
insert(x, cons(v, w)) → choose(x, cons(v, w), x, v) [1]
choose(x, cons(v, w), y, 0) → cons(x, cons(v, w)) [1]
choose(x, cons(v, w), 0, s(z)) → cons(v, insert(x, w)) [1]
choose(x, cons(v, w), s(y), s(z)) → choose(x, cons(v, w), y, z) [1]
choose(v0, v1, v2, v3) → nil [0]

The TRS has the following type information:
sort :: nil:cons → nil:cons
nil :: nil:cons
cons :: 0:s → nil:cons → nil:cons
insert :: 0:s → nil:cons → nil:cons
choose :: 0:s → nil:cons → 0:s → 0:s → nil:cons
0 :: 0:s
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(7) NarrowingProof (BOTH BOUNDS(ID, ID) transformation)

Narrowed the inner basic terms of all right-hand sides by a single narrowing step.

(8) Obligation:

Runtime Complexity Weighted TRS where critical functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

sort(nil) → nil [1]
sort(cons(x, nil)) → insert(x, nil) [2]
sort(cons(x, cons(x', y'))) → insert(x, insert(x', sort(y'))) [2]
insert(x, nil) → cons(x, nil) [1]
insert(x, cons(v, w)) → choose(x, cons(v, w), x, v) [1]
choose(x, cons(v, w), y, 0) → cons(x, cons(v, w)) [1]
choose(x, cons(v, w), 0, s(z)) → cons(v, insert(x, w)) [1]
choose(x, cons(v, w), s(y), s(z)) → choose(x, cons(v, w), y, z) [1]
choose(v0, v1, v2, v3) → nil [0]

The TRS has the following type information:
sort :: nil:cons → nil:cons
nil :: nil:cons
cons :: 0:s → nil:cons → nil:cons
insert :: 0:s → nil:cons → nil:cons
choose :: 0:s → nil:cons → 0:s → 0:s → nil:cons
0 :: 0:s
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(9) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

nil => 0
0 => 0

(10) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 1 }→ choose(x, 1 + v + w, y, z) :|: v >= 0, z >= 0, z' = x, z2 = 1 + z, x >= 0, y >= 0, z1 = 1 + y, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z2 = v3, v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, v3 >= 0, z' = v0
choose(z', z'', z1, z2) -{ 1 }→ 1 + v + insert(x, w) :|: z1 = 0, v >= 0, z >= 0, z' = x, z2 = 1 + z, x >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + x + (1 + v + w) :|: z1 = y, v >= 0, z' = x, z2 = 0, x >= 0, y >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ choose(x, 1 + v + w, x, v) :|: v >= 0, z' = x, x >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + x + 0 :|: z'' = 0, z' = x, x >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 2 }→ insert(x, 0) :|: x >= 0, z' = 1 + x + 0
sort(z') -{ 1 }→ 0 :|: z' = 0

(11) SimplificationProof (BOTH BOUNDS(ID, ID) transformation)

Simplified the RNTS by moving equalities from the constraints into the right-hand sides.

(12) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 1 }→ choose(z', 1 + v + w, z1 - 1, z2 - 1) :|: v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 1 }→ 1 + v + insert(z', w) :|: z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ choose(z', 1 + v + w, z', v) :|: v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 2 }→ insert(z' - 1, 0) :|: z' - 1 >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

(13) CpxRntsAnalysisOrderProof (BOTH BOUNDS(ID, ID) transformation)

Found the following analysis order by SCC decomposition:

{ insert, choose }
{ sort }

(14) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 1 }→ choose(z', 1 + v + w, z1 - 1, z2 - 1) :|: v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 1 }→ 1 + v + insert(z', w) :|: z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ choose(z', 1 + v + w, z', v) :|: v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 2 }→ insert(z' - 1, 0) :|: z' - 1 >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

Function symbols to be analyzed: {insert,choose}, {sort}

(15) IntTrsBoundProof (UPPER BOUND(ID) transformation)


Computed SIZE bound using CoFloCo for: insert
after applying outer abstraction to obtain an ITS,
resulting in: O(n1) with polynomial bound: 1 + z' + z''

Computed SIZE bound using CoFloCo for: choose
after applying outer abstraction to obtain an ITS,
resulting in: O(n1) with polynomial bound: 1 + z' + z''

(16) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 1 }→ choose(z', 1 + v + w, z1 - 1, z2 - 1) :|: v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 1 }→ 1 + v + insert(z', w) :|: z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ choose(z', 1 + v + w, z', v) :|: v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 2 }→ insert(z' - 1, 0) :|: z' - 1 >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

Function symbols to be analyzed: {insert,choose}, {sort}
Previous analysis results are:
insert: runtime: ?, size: O(n1) [1 + z' + z'']
choose: runtime: ?, size: O(n1) [1 + z' + z'']

(17) IntTrsBoundProof (UPPER BOUND(ID) transformation)


Computed RUNTIME bound using KoAT for: insert
after applying outer abstraction to obtain an ITS,
resulting in: O(n2) with polynomial bound: 2 + 4·z'' + 2·z''2

Computed RUNTIME bound using KoAT for: choose
after applying outer abstraction to obtain an ITS,
resulting in: O(n2) with polynomial bound: 4 + 4·z'' + 2·z''2 + z2

(18) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 1 }→ choose(z', 1 + v + w, z1 - 1, z2 - 1) :|: v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 1 }→ 1 + v + insert(z', w) :|: z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ choose(z', 1 + v + w, z', v) :|: v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 2 }→ insert(z' - 1, 0) :|: z' - 1 >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

Function symbols to be analyzed: {sort}
Previous analysis results are:
insert: runtime: O(n2) [2 + 4·z'' + 2·z''2], size: O(n1) [1 + z' + z'']
choose: runtime: O(n2) [4 + 4·z'' + 2·z''2 + z2], size: O(n1) [1 + z' + z'']

(19) ResultPropagationProof (UPPER BOUND(ID) transformation)

Applied inner abstraction using the recently inferred runtime/size bounds where possible.

(20) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 10 + 8·v + 4·v·w + 2·v2 + 8·w + 2·w2 + z2 }→ s1 :|: s1 >= 0, s1 <= 1 * z' + 1 * (1 + v + w) + 1, v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 3 + 4·w + 2·w2 }→ 1 + v + s'' :|: s'' >= 0, s'' <= 1 * z' + 1 * w + 1, z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 11 + 9·v + 4·v·w + 2·v2 + 8·w + 2·w2 }→ s' :|: s' >= 0, s' <= 1 * z' + 1 * (1 + v + w) + 1, v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 4 }→ s :|: s >= 0, s <= 1 * (z' - 1) + 1 * 0 + 1, z' - 1 >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

Function symbols to be analyzed: {sort}
Previous analysis results are:
insert: runtime: O(n2) [2 + 4·z'' + 2·z''2], size: O(n1) [1 + z' + z'']
choose: runtime: O(n2) [4 + 4·z'' + 2·z''2 + z2], size: O(n1) [1 + z' + z'']

(21) IntTrsBoundProof (UPPER BOUND(ID) transformation)


Computed SIZE bound using CoFloCo for: sort
after applying outer abstraction to obtain an ITS,
resulting in: O(n1) with polynomial bound: z'

(22) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 10 + 8·v + 4·v·w + 2·v2 + 8·w + 2·w2 + z2 }→ s1 :|: s1 >= 0, s1 <= 1 * z' + 1 * (1 + v + w) + 1, v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 3 + 4·w + 2·w2 }→ 1 + v + s'' :|: s'' >= 0, s'' <= 1 * z' + 1 * w + 1, z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 11 + 9·v + 4·v·w + 2·v2 + 8·w + 2·w2 }→ s' :|: s' >= 0, s' <= 1 * z' + 1 * (1 + v + w) + 1, v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 4 }→ s :|: s >= 0, s <= 1 * (z' - 1) + 1 * 0 + 1, z' - 1 >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

Function symbols to be analyzed: {sort}
Previous analysis results are:
insert: runtime: O(n2) [2 + 4·z'' + 2·z''2], size: O(n1) [1 + z' + z'']
choose: runtime: O(n2) [4 + 4·z'' + 2·z''2 + z2], size: O(n1) [1 + z' + z'']
sort: runtime: ?, size: O(n1) [z']

(23) IntTrsBoundProof (UPPER BOUND(ID) transformation)


Computed RUNTIME bound using KoAT for: sort
after applying outer abstraction to obtain an ITS,
resulting in: O(n3) with polynomial bound: 5 + 12·z' + 20·z'2 + 10·z'3

(24) Obligation:

Complexity RNTS consisting of the following rules:

choose(z', z'', z1, z2) -{ 10 + 8·v + 4·v·w + 2·v2 + 8·w + 2·w2 + z2 }→ s1 :|: s1 >= 0, s1 <= 1 * z' + 1 * (1 + v + w) + 1, v >= 0, z2 - 1 >= 0, z' >= 0, z1 - 1 >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 0 }→ 0 :|: z' >= 0, z'' >= 0, z1 >= 0, z2 >= 0
choose(z', z'', z1, z2) -{ 3 + 4·w + 2·w2 }→ 1 + v + s'' :|: s'' >= 0, s'' <= 1 * z' + 1 * w + 1, z1 = 0, v >= 0, z2 - 1 >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
choose(z', z'', z1, z2) -{ 1 }→ 1 + z' + (1 + v + w) :|: v >= 0, z2 = 0, z' >= 0, z1 >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 11 + 9·v + 4·v·w + 2·v2 + 8·w + 2·w2 }→ s' :|: s' >= 0, s' <= 1 * z' + 1 * (1 + v + w) + 1, v >= 0, z' >= 0, w >= 0, z'' = 1 + v + w
insert(z', z'') -{ 1 }→ 1 + z' + 0 :|: z'' = 0, z' >= 0
sort(z') -{ 4 }→ s :|: s >= 0, s <= 1 * (z' - 1) + 1 * 0 + 1, z' - 1 >= 0
sort(z') -{ 2 }→ insert(x, insert(x', sort(y'))) :|: z' = 1 + x + (1 + x' + y'), x >= 0, x' >= 0, y' >= 0
sort(z') -{ 1 }→ 0 :|: z' = 0

Function symbols to be analyzed:
Previous analysis results are:
insert: runtime: O(n2) [2 + 4·z'' + 2·z''2], size: O(n1) [1 + z' + z'']
choose: runtime: O(n2) [4 + 4·z'' + 2·z''2 + z2], size: O(n1) [1 + z' + z'']
sort: runtime: O(n3) [5 + 12·z' + 20·z'2 + 10·z'3], size: O(n1) [z']

(25) FinalProof (EQUIVALENT transformation)

Computed overall runtime complexity

(26) BOUNDS(1, n^3)